//
//  CustomGestureRecognizer.m
//  ResponderLab0
//
//  Created by Deheng.Xu on 12-6-29.
//  Copyright (c) 2012年 Deheng.Xu. All rights reserved.
//

#import "CustomGestureRecognizer.h"

@implementation CustomGestureRecognizer

@synthesize state;

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self performSelector:@selector(reset) withObject:nil afterDelay:0.];
#if DEBUG_GESTURE_LOGGING
    NSLog(@"%s", __func__);
#endif
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self performSelector:@selector(reset) withObject:nil afterDelay:0.];
#if DEBUG_GESTURE_LOGGING
    NSLog(@"%s", __func__);
#endif
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self performSelector:@selector(reset) withObject:nil afterDelay:0.];
#if DEBUG_GESTURE_LOGGING
    NSLog(@"%s", __func__);
#endif
}

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self performSelector:@selector(reset) withObject:nil afterDelay:0.];
#if DEBUG_GESTURE_LOGGING
    NSLog(@"%s", __func__);
#endif
}

- (void)reset
{
    if (![NSThread isMainThread]) {
        [self performSelectorOnMainThread:@selector(reset) withObject:nil waitUntilDone:NO];
        return;
    }
    
    self.state = UIGestureRecognizerStatePossible;
#if DEBUG_GESTURE_LOGGING
    NSLog(@"%s", __func__);
#endif
}

- (BOOL)canBePreventedByGestureRecognizer:(UIGestureRecognizer *)preventingGestureRecognizer
{
#if DEBUG_GESTURE_LOGGING
    NSLog(@"%s", __func__);
#endif
    return NO;
}

- (BOOL)canPreventGestureRecognizer:(UIGestureRecognizer *)preventedGestureRecognizer
{
#if DEBUG_GESTURE_LOGGING
    NSLog(@"%s", __func__);
#endif
    return NO;
}

@end
